home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2004 April / Gamestar_61_2004-04_dvdb.iso / DVDStar / Editace / hltp.exe / {app} / Applications / QuArK / plugins / maplinedit.py < prev    next >
Text File  |  2004-01-05  |  6KB  |  201 lines

  1. # QuArK  -  Quake Army Knife
  2. #
  3. # Copyright (C) 2001 The Quark Community
  4. # THIS FILE IS PROTECTED BY THE GNU GENERAL PUBLIC LICENCE
  5. # FOUND IN FILE "COPYING.TXT"
  6. #
  7. #$Header: /cvsroot/quark/runtime/plugins/maplinedit.py,v 1.5 2001/06/17 21:10:57 tiglari Exp $
  8.  
  9. Info = {
  10.    "plug-in":       "Linear Matrix Editor",
  11.    "desc":          "Edit matrix in linear specific",
  12.    "date":          "10 May 2001",
  13.    "author":        "tiglari",
  14.    "author e-mail": "tiglari@planetquake.com",
  15.    "quark":         "Quark 6.2" }
  16.  
  17.  
  18. import quarkx
  19. from quarkpy.maputils import *
  20. import quarkpy.qmacro
  21. import quarkpy.dlgclasses
  22. from quarkpy.qdictionnary import Strings
  23. from quarkpy.qeditor import matrix_rot_x
  24. from quarkpy.qeditor import matrix_rot_y
  25. from quarkpy.qeditor import matrix_rot_z
  26.  
  27.  
  28. class LinEditDlg (quarkpy.dlgclasses.LiveEditDlg):
  29.     #
  30.     # dialog layout
  31.     #
  32.  
  33.     endcolor = AQUA
  34.     size = (180,200)
  35.     dfsep = 0.45
  36.  
  37.     dlgdef = """
  38.         {
  39.             Style = "9"
  40.         Caption = "Linear Mapping Edit Dialog"
  41.  
  42.         scale: = 
  43.         {
  44.         Txt = "Scale"
  45.         Typ = "EF003"
  46.         Hint = "Scale X, Y, Z dimensions"
  47.         }
  48.  
  49.         sep: = {Typ="S" Txt=" "} 
  50.  
  51.         angles: =
  52.         {
  53.         Txt = "Angles"
  54.         Typ = "EF003"
  55.         Hint = "Pitch, Yaw, Roll angles (rotations around Y, Z, X" $0D " axes, in order"
  56.         }
  57.  
  58.         sep: = {Typ="S" Txt=" "}
  59.         
  60.         mirror: = {
  61.         Txt = "Mirror"
  62.         Typ = "X"
  63.         Hint = "Mirror in XZ plane.  Mirror effects can also be produced" $0D " with negative scale values"
  64.         }
  65.        
  66.         sep: = {Typ="S" Txt=" "} 
  67.         
  68.         shear: = {
  69.         Txt = "Shear"
  70.         Typ = "EF003"
  71.         Hint = "Shear angles: Z crunch (toward X axis),"$0D " Y-lift (out of XY plane), Y-twist (from Y-axis orientation)" $0D " For mirror-image, set Y-twist to 180"
  72.         }
  73.       
  74.         sep: = { Typ="S" Txt=""}
  75.  
  76.         exit:py = {Txt="" }
  77.     }
  78.     """
  79.  
  80. def macro_linedit(self):
  81.     editor = mapeditor()
  82.     if editor is None:
  83.         quarkx.msgbox('Unfortunately, you need to reselect me in the tree-view',
  84.            MT_INFORMATION,MB_OK)
  85.         return
  86.  
  87.     sel = editor.layout.explorer.uniquesel
  88.     if sel is None:
  89.         squawk("very wierd, no selection")
  90.         return
  91.  
  92.     class pack:
  93.         "just a place to stick stuff"
  94.     pack.sel = sel
  95.  
  96.     axes = quarkx.matrix('1 0 0 0 1 0 0 0 1').cols
  97.  
  98.     def setup(self, pack=pack, axes=axes):
  99.         pass
  100.         src = self.src
  101.         sel = pack.sel
  102.         linear = sel["linear"]
  103.         if linear is None:
  104.             linear = '1 0 0 0 1 0 0 0 1'
  105.         linear = quarkx.matrix(linear)
  106.         pack.linear = linear
  107.         cols = linear.cols
  108.         #
  109.         # get scale
  110.         #
  111.         src["scale"]=tuple(map(lambda v:abs(v), cols))
  112.         cols = tuple(map(lambda v:v.normalized, cols))    
  113.         #
  114.         # get rotations, cols[0] is 'rotated X axis, compute the others
  115.         #
  116.         yrot = cols[2]^cols[0]
  117.         zrot = cols[0]^yrot
  118.         pitch = math.asin(cols[0]*axes[2])
  119.         if abs(pitch)<89.99:
  120.             p = projectpointtoplane(cols[0],axes[2],
  121.               quarkx.vect(0,0,0), axes[2]).normalized
  122.             yaw = math.atan2(p.y, p.x)
  123.         else:
  124.             yaw = 0
  125.         y2 = matrix_rot_y(-pitch)*matrix_rot_z(-yaw)*yrot
  126.         roll = math.atan2(y2*axes[2], y2*axes[1])
  127.         src["angles"] = pitch/deg2rad, yaw/deg2rad, roll/deg2rad
  128.  
  129.         mat = matrix_rot_z(yaw)*matrix_rot_y(pitch)*matrix_rot_x(roll)
  130.  
  131.         cols = map(lambda v, mat=mat:~mat*v,cols)
  132.         
  133. #        cols = quarkx.matrix('1 0 0 0 1 0 0 0 1').cols
  134.         #
  135.         # Now get shear info (the cols have been rotated into
  136.         #   'canonical' position)
  137.         #
  138.         zxshear = math.asin(cols[0]*cols[2])
  139.         ylift = math.asin(axes[2]*cols[1])
  140.         p = projectpointtoplane(cols[1],axes[2],quarkx.vect(0,0,0),axes[2]).normalized
  141.         ytwist = math.atan2(p*axes[0], p*axes[1])
  142.         if ytwist > math.pi/2:
  143.             src["mirror"] = 1
  144.             ytwist = math.pi-ytwist
  145.         src["shear"] = zxshear/deg2rad, ylift/deg2rad, ytwist/deg2rad
  146.         
  147.  
  148.     def action(self, pack=pack, editor=editor):
  149.         src = self.src
  150.         zxshear, ylift, ytwist = tuple(map(lambda x:x*deg2rad, src["shear"]))
  151.         if src["mirror"]:
  152.             ytwist = math.pi-ytwist
  153. #        debug('yt '+`ytwist/deg2rad`)
  154.         colz = matrix_rot_y(-zxshear)*quarkx.vect(0,0,1)
  155.         coly = matrix_rot_x(ylift)*matrix_rot_z(-ytwist)*quarkx.vect(0,1,0)
  156.         cols = quarkx.vect(1,0,0), coly, colz
  157.         scale = src["scale"]
  158.         cols = map(lambda v,s:s*v, cols, scale)
  159.         angles = src["angles"]
  160.         pitch, yaw, roll = tuple(map(lambda a:a*deg2rad, angles))
  161.  
  162.         mat = matrix_rot_z(yaw)*matrix_rot_y(pitch)*matrix_rot_x(roll)
  163.                 
  164.         cols = map(lambda v,mat=mat:mat*v, cols)
  165.  
  166.  
  167.         #
  168.         # apply change  
  169.         #
  170.         linear = str(quarkx.matrix(cols[0],cols[1],cols[2]))
  171.         undo = quarkx.action()
  172.         if linear == '1 0 0 0 1 0 0 0 1':
  173.             linear = None
  174.         undo.setspec(pack.sel, 'linear', linear)
  175.         editor.ok(undo,"Set matrix scale")
  176.         
  177.  
  178.     LinEditDlg(quarkx.clickform, 'linedit', editor, setup, action)
  179.         
  180.     
  181.     
  182. quarkpy.qmacro.MACRO_linedit = macro_linedit
  183.  
  184. #$Log: maplinedit.py,v $
  185. #Revision 1.5  2001/06/17 21:10:57  tiglari
  186. #fix button captions
  187. #
  188. #Revision 1.4  2001/06/16 03:29:36  tiglari
  189. #add Txt="" to separators that need it
  190. #
  191. #Revision 1.3  2001/05/12 18:57:36  tiglari
  192. #add Mirror checkbox
  193. #
  194. #Revision 1.2  2001/05/12 12:24:23  tiglari
  195. #add rotate & shear
  196. #
  197. #Revision 1.1  2001/05/11 09:39:41  tiglari
  198. #kickoff with scale
  199. #
  200.  
  201.